fix: Set correct Content-Type when serving assets#136
Closed
sbernauer wants to merge 1 commit into
Closed
Conversation
Users have reported problems using either Chrome, Edge or Safari getting the error message failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec. The root cause was that we set the Content-Type header twice, once to application/octet-stream and the second to text/javascript. With this fix only a single (correct) Content-Type header is sent.
nightkr
suggested changes
Nov 3, 2023
Comment on lines
+23
to
+24
| async fn asset(mut headers: HeaderMap, Path(name): Path<String>) -> impl IntoResponse { | ||
| headers.insert( |
Contributor
There was a problem hiding this comment.
This doesn't do what you want it to. The HeaderMap argument isn't some base set of headers defined by the framework, but the headers sent by the client. What this PR actually does is to reflect any headers sent by the user back at them.
Contributor
There was a problem hiding this comment.
You can test this yourself: curl 'http://localhost:8000/ui/assets/index-1272d2e9.js' -H 'foo: bar' -D- -o /dev/null | grep foo.
Member
Author
There was a problem hiding this comment.
Close enough ^^
Good catch, thx!
Comment on lines
+20
to
+22
| /// Adds (or replaces) the Content-Type header with the type of the served asset. | ||
| /// So far only javascript and css are supported, for all the other types | ||
| /// `application/octet-stream` will be used. |
Contributor
There was a problem hiding this comment.
This is a detail of the function, but not its primary purpose. This should be either a subsection of the doccomment, or a regular comment inside of the function.
Member
Author
|
Superseded by #137 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users have reported problems using either Chrome, Edge or Safari getting the error message
The root cause was that we set the Content-Type header twice, once to application/octet-stream and the second to text/javascript. With this fix only a single (correct) Content-Type header is sent.
Thanks @Techassi for the help!
Description
Please add a description here. This will become the commit message of the merge request later.
Definition of Done Checklist
Once the review is done, comment
bors r+(orbors merge) to merge. Further information